package robotia;

import simbad.gui.Simbad;
import simbad.sim.*;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

public class Example1 {

    /** Describe the robot */
    static public class RobotIA extends Agent {

        RangeSensorBelt sonars;
        CameraSensor camera;

        public static void main(String[] args) {
            // request antialising
            System.setProperty("j3d.implicitAntialiasing", "true");
            // create Simbad instance with given environment
            Simbad frame = new Simbad(new MyEnvironement(), false);
        }

        public RobotIA(Vector3d position, String name) {
            super(position, name);
            // Add camera
            camera = RobotFactory.addCameraSensor(this);
            // Add sonars
            sonars = RobotFactory.addSonarBeltSensor(this);

        }

        /** This method is call cyclically (20 times per second)  by the simulator engine. */
        @Override
        public void performBehavior() {

            // progress at 0.5 m/s
            setTranslationalVelocity(0.5);
            // frequently change orientation
            if ((getCounter() % 100) == 0) {
                setRotationalVelocity(Math.PI / 2 * (0.5 - Math.random()));
            }

            // print front sonar every 100 frames
            if (getCounter() % 100 == 0) {
                System.out.println("Sonar num 0  = " + sonars.getMeasurement(0));
            }

        }
    }

    /** Describe the environement */
    static public class MyEnvironement extends EnvironmentDescription {

        public MyEnvironement() {
            light1IsOn = true;
            light2IsOn = false;
            Wall w1 = new Wall(new Vector3d(9, 0, 0), 19, 1, this);//Pared 1
            w1.rotate90(1);
            add(w1);
            Wall w2 = new Wall(new Vector3d(-9, 0, 0), 19, 2, this);//Pared 2
            w2.rotate90(1);
            add(w2);
            Wall w3 = new Wall(new Vector3d(0, 0, 9), 19, 1, this);//Pared 3
            add(w3);
            Wall w4 = new Wall(new Vector3d(0, 0, -9), 19, 2, this);//Pared 4
            add(w4);
            Box b1 = new Box(new Vector3d(-3, 0, -3), new Vector3f(1, 1, 1), this); //caja
            add(b1);
            add(new Arch(new Vector3d(3, 0, -3), this));//Arco
            add(new RobotIA(new Vector3d(0, 0, 0), "RobotIA"));
        }
    }
}
